package com.jfinal.weixin.sdk.api;

import java.util.Map;

import org.apache.log4j.Logger;

import com.jfinal.kit.PropKit;
import com.jfinal.weixin.sdk.utils.HttpUtils;

import cn.com.longfuinfo.wx.exception.SaveException;

public class OrderExpireApi {
	private static Logger log = Logger.getLogger(MsgApi.class);
	private static ApiResult post(String baseUrl, String jsonStr) {
		String url = baseUrl + AccessTokenApi.getAccessTokenStr();
		String jsonResult = HttpUtils.post(url, jsonStr);
		return new ApiResult(jsonResult);
	}
	
	/**
	 * 订单到期提醒的情况下向用户推送一条消息
	 */
	private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";

	
	public static ApiResult editWX_opinion(Map<String,Object> mapParam) throws SaveException{
	    //模板Id
		String template_id=PropKit.get("constants.template_orderExpireApi");
		try {
			log.info("OPENID:::::"+mapParam.get("OPENID"));
			String jsonParam = "{\"touser\":\""+mapParam.get("OPENID")+"\",\"template_id\":\""+template_id+"\","
					+ "\"url\":\""+mapParam.get("url")+"\","
					+ "\"data\": {\"first\":{\"value\": \""+mapParam.get("firstDATA")+"\",\"color\":\"#353535\""+"},"
					+ "\"keyword1\":{\"value\": \""+mapParam.get("keyword1DATA")+"\",\"color\":\"#555e94\""+"},"
					+ "\"keyword2\":{\"value\": \""+mapParam.get("keyword2DATA")+"\",\"color\":\"#555e94\""+"},"
					+ "\"keyword3\":{\"value\": \""+mapParam.get("keyword3DATA")+"\",\"color\":\"#555e94\""+"},"
					+ "\"remark\":{\"value\": \""+mapParam.get("remarkDATA")+"\",\"color\":\"#353535\""+"}"
					+ "}}";

			log.info("jsonParam::::"+jsonParam);
			return post(sendMsgUrl, jsonParam);
		} catch (Exception e) {
			log.error(e.getMessage());
			throw new SaveException(e.getMessage(), e);
		}
	}
}
